const queryRules = {
	datetime: [
        {required: true, message: '请输选择月份', trigger: 'blur'}
    ]
}

// 注释
let app = new Vue({
	el: "#app",
	data() {
		return {
		    data : [],
			theader:[],//表示多少周，每周多少天
			spanArr:[],
			leftbar_show: true,
			queryForm: {
				datetime: "",
			},
			tableHeight: window.innerHeight - 90,

			transFormVisible : false,
			transFormData: [],
		}
	},
	methods: {
		// 显示侧边栏
		showLeftBar() {
			if (this.leftbar_show) {
				this.leftbar_show = false
			} else {
				this.leftbar_show = true
			}
		},
        // 表格多选
		handleSelectionChange(val) {
			this.multipleSelection = val;
		},
        //控制合并行
		objectSpanMethod({ row,column,rowIndex,columnIndex }) {
			if (columnIndex === 0 ) {//第一列
    			//[3，0，0，2，0]
				if (this.spanArr[rowIndex] > 0) {//判断这一行是否合并
//                    console.log(this.data[-1]);
                    return {
                        // [0,0] 表示这一行不显示， [2,1]表示行的合并数
                        rowspan: this.spanArr[rowIndex],//表示行的合并数
                        colspan: 1//表示列的合并数
                    };
				} else {
                   return {
                        rowspan: 0,
                        colspan: 0
                    };
                }
			}
		},
		//根据条件查询
		start() {
		    if (this.queryForm.datetime === "" || this.queryForm.datetime === null) {
		        alert("请选择月份！");
		        return;
		    }
			this.query()

		},
		// 查询
		async query() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.post('api/personalsales/query', this.queryForm);
				if (res.code === 200) {
					this.data = res.data.data;
        			console.log(this.data);
					this.theader = res.data.theader;
					this.spanArr = res.data.spanArr;
					this.$message.success(res.message);
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('查询请求出错！', e.message);
			}
			// 关闭加载框
			loading.close();
		},
		// 查询流转单信息
		async getTransFormDatas(row_id) {
		    this.transFormVisible = true;
		    // 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.post('api/personalsales/getTransFormDatas/' + row_id);
				if (res.code === 200) {
					this.transFormData = res.data.data;
					this.$message.success(res.message);
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('查询请求出错！', e.message);
			}
			// 关闭加载框
			loading.close();
		},

		getSummaries(param) {
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总计';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          if (index === 5 || index === 6 || index === 7) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += '';
          } else {
            sums[index] = '';
          }
        });

        return sums;
      }

	},
	async mounted() {
		// 自动调整表格高度
		window.onresize = () => {
			return (() => {
				this.tableHeight = window.innerHeight - 90
			})()
		}
	}
});